home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / binutils.7 / binutils / binutils-2.7 / ld / ldemul.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-04  |  4.7 KB  |  263 lines

  1. /* ldemul.c -- clearing house for ld emulation states
  2.    Copyright (C) 1991, 1993 Free Software Foundation, Inc.
  3.  
  4. This file is part of GLD, the Gnu Linker.
  5.  
  6. GLD is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GLD is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GLD; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
  19.  
  20. #include "bfd.h"
  21. #include "sysdep.h"
  22.  
  23. #include "ld.h"
  24. #include "ldemul.h"
  25. #include "ldmisc.h"
  26. #include "ldexp.h"
  27. #include "ldlang.h"
  28. #include "ldfile.h"
  29. #include "ldmain.h"
  30. #include "ldemul-list.h"
  31.  
  32. ld_emulation_xfer_type *ld_emulation;
  33.  
  34. void
  35. ldemul_hll(name)
  36.      char *name;
  37. {
  38.   ld_emulation->hll(name);
  39. }
  40.  
  41.  
  42. void ldemul_syslib(name)
  43.      char *name;
  44. {
  45.   ld_emulation->syslib(name);
  46. }
  47.  
  48. void
  49. ldemul_after_parse()
  50. {
  51.   ld_emulation->after_parse();
  52. }
  53.  
  54. void
  55. ldemul_before_parse()
  56. {
  57.   ld_emulation->before_parse();
  58. }
  59.  
  60. void
  61. ldemul_after_open ()
  62. {
  63.   ld_emulation->after_open ();
  64. }
  65.  
  66. void 
  67. ldemul_after_allocation()
  68. {
  69.   ld_emulation->after_allocation();
  70. }
  71.  
  72. void 
  73. ldemul_before_allocation()
  74. {
  75.   if (ld_emulation->before_allocation)
  76.     ld_emulation->before_allocation();
  77. }
  78.  
  79.  
  80. void
  81. ldemul_set_output_arch()
  82. {
  83.   ld_emulation->set_output_arch();
  84. }
  85.  
  86. void
  87. ldemul_finish()
  88. {
  89.   if (ld_emulation->finish)
  90.     ld_emulation->finish();
  91. }
  92.  
  93. void
  94. ldemul_set_symbols()
  95. {
  96.   if (ld_emulation->set_symbols)
  97.     ld_emulation->set_symbols();
  98. }
  99.  
  100. void
  101. ldemul_create_output_section_statements()
  102. {
  103.   if (ld_emulation->create_output_section_statements)
  104.     ld_emulation->create_output_section_statements();
  105. }
  106.  
  107. char *
  108. ldemul_get_script(isfile)
  109.      int *isfile;
  110. {
  111.   return ld_emulation->get_script(isfile);
  112. }
  113.  
  114. boolean
  115. ldemul_open_dynamic_archive (arch, search, entry)
  116.      const char *arch;
  117.      search_dirs_type *search;
  118.      lang_input_statement_type *entry;
  119. {
  120.   if (ld_emulation->open_dynamic_archive)
  121.     return (*ld_emulation->open_dynamic_archive) (arch, search, entry);
  122.   return false;
  123. }
  124.  
  125. boolean
  126. ldemul_place_orphan (file, s)
  127.      lang_input_statement_type *file;
  128.      asection *s;
  129. {
  130.   if (ld_emulation->place_orphan)
  131.     return (*ld_emulation->place_orphan) (file, s);
  132.   return false;
  133. }
  134.  
  135. int
  136. ldemul_parse_args (argc, argv)
  137.      int argc;
  138.      char **argv;
  139. {
  140.   /* Try and use the emulation parser if there is one. */
  141.   if (ld_emulation->parse_args)
  142.     {
  143.       return ld_emulation->parse_args (argc, argv);
  144.     }
  145.   return 0;
  146. }
  147.  
  148. /* Let the emulation code handle an unrecognized file.  */
  149.  
  150. boolean
  151. ldemul_unrecognized_file (entry)
  152.      lang_input_statement_type *entry;
  153. {
  154.   if (ld_emulation->unrecognized_file)
  155.     return (*ld_emulation->unrecognized_file) (entry);
  156.   return false;
  157. }
  158.  
  159. char *
  160. ldemul_choose_target()
  161. {
  162.   return ld_emulation->choose_target();
  163. }
  164.  
  165. /* The default choose_target function.  */
  166.  
  167. char *
  168. ldemul_default_target()
  169. {
  170.   char *from_outside = (char *) getenv(TARGET_ENVIRON);
  171.   if (from_outside != (char *)NULL)
  172.     return from_outside;
  173.   return ld_emulation->target_name;
  174. }
  175.  
  176. void 
  177. after_parse_default()
  178. {
  179.  
  180. }
  181.  
  182. void
  183. after_open_default ()
  184. {
  185. }
  186.  
  187. void
  188. after_allocation_default()
  189. {
  190.  
  191. }
  192.  
  193. void
  194. before_allocation_default()
  195. {
  196.  
  197. }
  198.  
  199. void
  200. set_output_arch_default()
  201. {
  202.   /* Set the output architecture and machine if possible */
  203.   bfd_set_arch_mach(output_bfd,
  204.                 ldfile_output_architecture, ldfile_output_machine);
  205. }
  206.  
  207. /*ARGSUSED*/
  208. void
  209. syslib_default(ignore)
  210.      char  *ignore;
  211. {
  212.   info_msg ("%S SYSLIB ignored\n");
  213. }
  214.  
  215. /*ARGSUSED*/
  216. void
  217. hll_default(ignore)
  218.      char  *ignore;
  219. {
  220.   info_msg ("%S HLL ignored\n");
  221. }
  222.  
  223. ld_emulation_xfer_type *ld_emulations[] = { EMULATION_LIST };
  224.  
  225. void
  226. ldemul_choose_mode(target)
  227.      char *target;
  228. {
  229.     ld_emulation_xfer_type **eptr = ld_emulations;
  230.     /* Ignore "gld" prefix. */
  231.     if (target[0] == 'g' && target[1] == 'l' && target[2] == 'd')
  232.     target += 3;
  233.     for (; *eptr; eptr++)
  234.       {
  235.     if (strcmp(target, (*eptr)->emulation_name) == 0)
  236.       {
  237.         ld_emulation = *eptr;
  238.         return;
  239.       }
  240.       }
  241.     einfo ("%P: unrecognised emulation mode: %s\n", target);
  242.     einfo ("Supported emulations: ", program_name);
  243.     ldemul_list_emulations (stderr);
  244.     einfo ("%F\n");
  245. }
  246.  
  247. void
  248. ldemul_list_emulations (f)
  249.      FILE *f;
  250. {
  251.   ld_emulation_xfer_type **eptr = ld_emulations;
  252.   boolean first = true;
  253.  
  254.   for (; *eptr; eptr++)
  255.     {
  256.       if (first)
  257.     first = false;
  258.       else
  259.     fprintf (f, " ");
  260.       fprintf (f, "%s", (*eptr)->emulation_name);
  261.     }
  262. }
  263.